package com.softdev.service.impl;

import com.softdev.pojo.Risk;
import com.softdev.repo.RiskRepository;
import com.softdev.service.RiskService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
public class RiskServiceImpl implements RiskService {

    @Resource
    private RiskRepository riskRepository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean add(Risk risk) {

        riskRepository.save(risk);

        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean remove(Long[] riskIds) {

        riskRepository.deleteAllById(Arrays.asList(riskIds));

        return true;
    }

    @Override
    public List<Risk> getAll() {
        return riskRepository.findAll();
    }
}
